package cn.edu.njust.alg;

public class SearchImpl {
	
	public static int binarySearch(int[]a,int begin,int end,int x) {
		
		int mid =(begin+end)/2;
		System.out.println("mid:"+mid);
		if(begin<=end){
			if(a[mid]==x){
				return mid;
			}else if(a[mid]<x){
				return binarySearch(a, begin, mid-1, x);
			}else if(a[mid]>x){
				return binarySearch(a, mid+1, end, x);
			}
			
		}
		return -1;
	}

	public static void main(String[] args) {

		int[]a = {212,100,89,73,56};
		int index = binarySearch(a, 0, a.length-1, 212);
		System.out.println(index);
	}

}
